package com.mc.stack;

/**
 * @Description: 链栈
 * @Author: MoChen
 */
public class HLinkedStack {

    private class HLSNode{

        private int data;
        private HLSNode next;

        public HLSNode(int data) {
            this.data = data;
        }
    }

    HLSNode head = null;

    HLinkedStack(){

    }

    // 初始化链栈
    void initLinkedStack(){
        // 头结点初始为空
        head.next = null;
    }

    // 头插
    boolean insertPriorNode(int e){
        HLSNode s = new HLSNode(e);
        HLSNode p = head.next;
        s.next = p.next;
        p.next = s;
        return true;
    }

    // 头删
    boolean deletePriorNode(){
        HLSNode p = head.next;
        HLSNode q = p.next;
        p.data = p.next.data; // 和后继结点交换数据域
        p.next = q.next; // 将q结点从链中断开
        return true;
    }

}
